package io.renren.modules.member.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.member.entity.StandardBmiEntity;
import io.renren.modules.member.service.StandardBmiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 学员
 *
 * @author Mark 军事体育训练考核系统
 */
@RestController
@RequestMapping("standard/bmi")
public class StandardBmiController {

    private final Logger logger = LoggerFactory.getLogger(StandardBmiController.class);

    @Autowired
    private StandardBmiService bmiService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("standard:comm:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bmiService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("standard:comm:info")
    public R info(@PathVariable("id") Long id){
        StandardBmiEntity entity = bmiService.getById(id);
        return R.ok().put("entity", entity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("standard:comm:save")
    public R save(@RequestBody StandardBmiEntity entity){
        //校验类型
        ValidatorUtils.validateEntity(entity);
        bmiService.save(entity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("standard:comm:update")
    public R update(@RequestBody StandardBmiEntity entity){
        //校验类型
        ValidatorUtils.validateEntity(entity);
        bmiService.updateById(entity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("standard:comm:delete")
    public R delete(@RequestBody Long[] ids){
        bmiService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
